package com.ming.controller;

import com.ming.common.Result;
import com.ming.common.validator.ValidatorUtil;
import com.ming.domain.SysRole;
import com.ming.from.SysRoleForm;
import com.ming.query.SysRoleQuery;
import com.ming.service.SysRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("sysrole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;


    @RequestMapping("page.do")
    public Object page(SysRoleQuery query) {
        Result rs = sysRoleService.queryPage(query);
        return rs;
    }

    @RequestMapping("roles.do")
    public Object queryAllRoles(){
        Result rs = sysRoleService.queryAllRoles();
        return rs;
    }

    //查询用户角色
    @RequestMapping("userRoles.do")
    public Object queryUserRoles(SysRoleQuery query){
        Result rs = sysRoleService.queryUserRole(query);
        return rs;
    }

    /**
     * 根据角色id 查询权限
     * @param roleId
     * @return
     */
    @RequestMapping("rolePers.do")
    public Object rolePers(Integer roleId){
        Result rs = sysRoleService.rolePers(roleId);
        return rs;
    }

    /**
     * 设置角色权限
     * @param roleId
     * @param pId
     * @return
     */
    @RequestMapping("setPermissions.do")
    public Object setPermissions(Integer roleId, @RequestParam("pId") List<Integer> pId){
        Result rs = sysRoleService.setPermissions(roleId,pId);
        return rs;
    }

    /**
     * 修改角色信息
     * @param form
     * @return
     */
    @RequestMapping("update.do")
    public Object update(SysRoleForm form) {
        ValidatorUtil.validator(form);
        Result rs = sysRoleService.update(form);
        return rs;
    }

    /**
     * 添加角色
     * @param form
     * @return
     */
    @RequestMapping("add.do")
    public Object add(SysRoleForm form) {
        ValidatorUtil.validator(form);
        Result rs = sysRoleService.add(form);
        return rs;
    }



}
